package cn.topcodes.tcsf.wechat.web.controller;

import cn.topcode.unicorn.wxsdk.message.reply.ReplyMessage;
import cn.topcodes.tcsf.admin.commons.api.domain.ApiResponseEntity;
import cn.topcodes.tcsf.wechat.service.WechatKfMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Unicorn on 2017/8/17.
 */
@Controller
@RequestMapping("/admin/wechat/kf-message")
public class KfMessageController {

    @Autowired
    private WechatKfMessageService wechatKfMessageService;

    @ResponseBody
    @RequestMapping(value = "send-text", method = RequestMethod.POST)
    public ApiResponseEntity sendText(
            @RequestParam(required = true) String mpId,
            @RequestParam(required = true) String openId,
            @RequestParam(required = true) String text,
            @RequestParam(required = false) String kfAccount) {
        this.wechatKfMessageService.sendText(mpId, openId, text, kfAccount);
        return ApiResponseEntity.buildOK();
    }

    @ResponseBody
    @RequestMapping(value = "send-media", method = RequestMethod.POST)
    public ApiResponseEntity sendMedia(
            @RequestParam(required = true) String mpId,
            @RequestParam(required = true) String openId,
            @RequestParam(required = true) String mediaId,
            @RequestParam(required = true) String msgType,
            @RequestParam(required = false) String kfAccount
    ) {
        switch(msgType) {
            case ReplyMessage.MSG_TYPE_IMAGE:
                this.wechatKfMessageService.sendImage(mpId, openId, mediaId, kfAccount);
                break;
            case ReplyMessage.MSG_TYPE_MUSIC:

                break;
            case ReplyMessage.MSG_TYPE_NEWS:

                break;
            case ReplyMessage.MSG_TYPE_VIDEO:
//                this.wechatKfMessageService.sendVideo(openId, mediaId, kfAccount);
                break;
            case ReplyMessage.MSG_TYPE_VOICE:
                this.wechatKfMessageService.sendVoice(mpId, openId, mediaId, kfAccount);
                break;
                default:
                    return ApiResponseEntity.buildFailed("类型不支持");
        }
        return ApiResponseEntity.buildOK();
    }

}
